package com.qq.xrx1002.androidgame;

import org.cocos2d.actions.base.CCRepeatForever;
import org.cocos2d.actions.interval.CCAnimate;
import org.cocos2d.nodes.CCAnimation;
import org.cocos2d.nodes.CCSprite;
import org.cocos2d.nodes.CCSpriteFrame;

import java.util.ArrayList;
import java.util.Locale;

/**
 * Created by Alyson on 2018/11/14.
 */

public abstract class Plant extends CCSprite{
    private int HP=100;//生成一个整型值的生命
    private int price;//设置植物价格
    public Plant(String format,int number){
        super(String.format(Locale.CHINA,format,0));//调用精灵的帧方法
        setAnchorPoint(0.5f,0);//设置位置
        ArrayList<CCSpriteFrame> frames=new ArrayList<>();//使用数组列表来对精灵
        for (int i = 0; i <number ; i++) {
            CCSpriteFrame ccSpriteFrame=CCSprite.sprite(String.format(Locale.CHINA,format,i))
                    .displayedFrame();
            frames.add(ccSpriteFrame);
        }
        CCAnimation ccAnimation=CCAnimation.animationWithFrames(frames,0.2f);//帧动画
        CCAnimate ccAnimate=CCAnimate.action(ccAnimation,true);//帧重复，确定为真
        CCRepeatForever ccRepeatForever=CCRepeatForever.action(ccAnimate);//帧动画永远重复
        runAction(ccRepeatForever);
    }

    public int getHP() {
        return HP;
    }

    public void setHP(int HP) {
        this.HP = HP;
    }

    public void hurtCompute(int hurt){//伤害的计算
        HP-=hurt;
        if (HP<0){
            HP=0;
        }
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }
}
